const fs = require("fs");
const path = require("path");

const names = [];
console.log("create...");


const lineReader = require("readline").createInterface({
  input: require("fs").createReadStream(
    path.join(__dirname, "../assets/fonts/iconfont.svg")
  )
});

lineReader.on("line", function(line) {
  let words = line.split(" ");
  if (words[4] === "<glyph") {
    let [key, value] = [words[5].slice(12, -1), words[6].slice(11, -2)];
    if (value) {
      names.push(' static const int ' + key.replace('-','_') + ' = ' + value +';');
    }
  }
});
lineReader.on("close", function() {
  return fs.writeFile(
    path.resolve(__dirname, "../lib/resources/icon/iconfont_name_reflect.dart"),
    "class IconNameMap {\n" + names.join("\n") + "\n}",
    function(err) {
      if (err) {
        throw new Error(err);
      } else {
        console.log("create svg map successe.");
      }
    }
  );
});
